<template>
    <view class="navbar">
        <view class="navbar-fixed">
            <!-- 状态栏小程序撑起高度 -->
            <view :style="{ height: statusBarHeight + 'px' }"></view>
            <!-- , width: windowWidth + 'px' -->
            <view class="navbar-content" :style="{ height: navBarHeight + 'px' }">
                <view class="li" @click="on_goUrl">
                    <view class="img">
                        <image src="https://bpy.noogka.com/icon/leftIcon.png"></image>
                    </view>
                </view>
                <view class="li ">商品详情</view>
                <view class="li"></view>
            </view>
        </view>
        <!-- 需要添加占位符高度  状态栏高度+导航栏高度（否则下面tab会塌陷）-->
        <view :style="{ height: statusBarHeight + navBarHeight + 'px' }"></view>
    </view>
</template>

<script>
export default {
    name: 'navbar',
    props: {
        type: {
            default: false
        },
        value: {
            default: ''
        }
    },
    data() {
        return {
            statusBarHeight: 20,/* 状态栏高度 */
            navBarHeight: 60,/* 导航栏高度 */
            windowWidth: 375,/* 窗口宽度 */
            /* 设定状态栏默认高度 */
            valueData: ''/* 导航栏搜索框的值 */
        };
    },
    created() {
        // 获取手机系统信息
        const info = uni.getSystemInfoSync()
        // 设置状态栏高度（H5顶部无状态栏小程序有状态栏需要撑起高度）
        this.statusBarHeight = info.statusBarHeight
        this.windowWidth = info.windowWidth
        // 除了h5 app mp-alipay的情况下执行
        // #ifndef H5 || APP-PLUS || MP-ALIPAY
        // 获取胶囊的位置
        const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
        console.log(menuButtonInfo);
        // (胶囊底部高度 - 状态栏的高度) + (胶囊顶部高度 - 状态栏内的高度) = 导航栏的高度
        this.navBarHeight = (menuButtonInfo.bottom - info.statusBarHeight) + (menuButtonInfo.top - info.statusBarHeight)
        this.windowWidth = menuButtonInfo.left
        // #endif
    },
    mounted() {
        if (this.type == 2) {
            console.log('触发了')
            this.valueData = this.value
        }
    },
    methods: {
        on_goUrl() {
            uni.navigateBack();
        },
        on_confirm() {
            console.log('触发')
            this.$emit('on_confirm', this.valueData)
        }
    }
}
</script>

<style lang="scss">
.navbar {
    .navbar-fixed {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 99;
        width: 100%;
        background-color: #87C81F;

        .navbar-content {
            display: flex;
            align-items: center;
            padding: 0 20rpx;
            box-sizing: border-box;
            z-index: 999;
            background-color: #87C81F;
            color: #fff;
            justify-content: space-between;
            font-size: 32rpx;
            font-weight: 700;
            width: 100%;

            .li {
                width: 33%;
                display: flex;
                align-items: center;
                justify-content: center;
                .img {
                    width: 24px;
                    height: 24px;

                    image {
                        width: 100%;
                        height: 100%;
                    }
                }
            }

            .li:nth-child(1) {
                justify-content: flex-start;
            }


        }
    }
}
</style>